package DBLayer;
import model.*;

	import java.sql.*;

public class DBStockLog {

	private  Connection con;
	
	public DBStockLog() {
		con = DBConnection.getInstance().getDBcon();
	}
	   
	public int insertStockLog(StockLog sl) throws Exception {  
		int nextID = GetMax.getMaxID("Select max(stockLogID) from StockLog");
		nextID = nextID + 1;
		System.out.println("next ID = " +  nextID);
	  
		int rg = -1;
	       
		String query="INSERT INTO StockLog(stockLogID, empID, productID, stockLogAmount)  VALUES('"+
		nextID + "','" +
		sl.getEmployee().getEmpID() + "','" +
		sl.getProductID() + "','" +
		sl.getAmount() + "')";
	                  
	  	System.out.println("insert : " + query);
	    
	  	try {
	    	Statement stmt = con.createStatement();
	      	stmt.setQueryTimeout(5);
	     	rg = stmt.executeUpdate(query);
	     	stmt.close();
	 	}
	    catch(SQLException ex) {
	    	System.out.println("StockLog not created");
	      	throw new Exception ("StockLog is not inserted correctly");
	 	}
	    	return(rg);
	}
	 
}  
	    
